package daos

import model.Villano
import org.junit.Before
import org.junit.Test

import static org.junit.Assert.*

class VillanoDAOTest {
	
	var VillanoDAO villanoDAOTest = new VillanoDAO
	var Villano mockVillano = new Villano()
	
	@Before
	public def void setUp() {
		this.mockVillano.nombre = "VillanoTest"
	} 
	
	@Test
	public def void agregarVillanoTest() {
		this.villanoDAOTest.agregar(this.mockVillano)
		assertEquals("Deberia haber agregado al villano", this.villanoDAOTest.villanos.size, 1)
	}
	
	@Test(expected = RuntimeException)
	public def void agregarDosVecesAlMismoVillanoTest(){
		this.villanoDAOTest.agregar(this.mockVillano)
		this.villanoDAOTest.agregar(this.mockVillano)
	}
	
	@Test
	public def void quitarVillanoTest() {
		this.villanoDAOTest.agregar(this.mockVillano)
		this.villanoDAOTest.quitar(this.mockVillano)
		assertEquals("Deberia haber quitado al villano", this.villanoDAOTest.villanos.size, 0)
		
	}

	@Test
	public def void buscarVillanoTest() {
		this.villanoDAOTest.agregar(this.mockVillano)
		assertEquals("Deberia ser el mismo villano", this.mockVillano, this.villanoDAOTest.buscar(this.mockVillano.nombre))
	}

}